package com.framework.surfaces;

import java.util.Timer;
import java.util.TimerTask;

import com.framework.R;

import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class TDSurfacesActivity extends Activity implements SurfaceHolder.Callback {
	private SurfaceView mSurfaceView;
	private SurfaceHolder mSurfaceHolder;
	private Timer mTimer;
	private TimerTask mTask;
	private int centerX;
	private int centerY;
	private int number;
	private boolean simpleSentry = false;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_surfaces);
		mSurfaceView = (SurfaceView) findViewById(R.id.surfaces);
//		mSurfaceView.setO
		mSurfaceHolder = mSurfaceView.getHolder();
		mSurfaceHolder.addCallback(this);
		centerX = getWindowManager().getDefaultDisplay().getWidth() /2;
		centerY = getWindowManager().getDefaultDisplay().getHeight() /2;
		mTimer = new Timer();
		mTask = new TimerTask(){

			@Override
			public void run() {
				// TODO Auto-generated method stub
				simpleDraw();
			}
			
		};
		mTimer.schedule(mTask, 1000, 1000);
	}

	@Override
synchronized	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
synchronized	public void surfaceCreated(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		simpleSentry =true;
	}

	@Override
	synchronized	public void surfaceDestroyed(SurfaceHolder holder) {
		// TODO Auto-generated method stub
		simpleSentry = false;
	}
	
 synchronized private void simpleDraw(){
	 if(simpleSentry){
		 Canvas mCanvas = mSurfaceHolder.lockCanvas();
			Paint paint = new Paint();
			paint.setColor(Color.BLUE);
			paint.setStrokeWidth(2);
			paint.setTextSize(30);
			mCanvas.drawRGB(0, 0, 0);
			mCanvas.drawLine(0f, 0f, 100, 100, paint);
			number ++;
			mCanvas.drawText("seraph==="+number, 100, 100, paint);
			mSurfaceHolder.unlockCanvasAndPost(mCanvas);
			Log.d("com.seraph.td.surface","number ===" + number);
	 }
		
 }

}
